<template>
  <div class="box">
    <div class="header">
      <div class="header_one" @click="Gohome">西安</div>
      <div class="header_two">
        <van-search
          v-model="value"
          shape="round"
          background="#ee0a24"
          placeholder="请输入搜索关键词" label="地址" @click="$router.push('/list')"/>
      </div>
      <div class="header_three">
      <button @click="toLogin">登录</button>
      </div>
    </div>
    <!-- 轮播图 -->
    <div class="main" @scroll="scrollMe" ref="main">
      <van-pull-refresh v-model="isLoading" @refresh="onRefresh">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in bannerList" :key="index">
            <img :src="item.imgurl" />
          </van-swipe-item>
        </van-swipe>
        <!-- grid布局 -->
        <div class="top10">
          <van-grid :column-num="5" :border="false" :icon-size="35" :gutter="0">
            <van-grid-item
              v-for="item in navList"
              :key="item.navid"
              :icon="item.imgurl"
              :text="item.title"
            />
          </van-grid>
        </div>
        <!-- 倒计时 -->
        <div class="djs">
        <div class="djs-one"  >京东秒杀
          
        </div>
        <div class="top10">
          <van-count-down  :time="time" >
            <template #default="timeData">
              <span class="block">{{ timeData.hours }}</span>
              <span class="colon">:</span>
              <span class="block">{{ timeData.minutes }}</span>
              <span class="colon">:</span>
              <span class="block">{{ timeData.seconds }}</span>
            </template>
          </van-count-down>
        </div>
        <div class="djs-two">爆款轮番秒
          
        </div>
        </div>
        <!-- 图标域 -->

        <div class="top10">
          <ul class="seckill">
            <li
              v-for="item in seckillList"
              :key="item.proid"
              @click="jumpTo(item.proid)"
            >
              <van-image width="60" height="60" :src="item.img1" />
              <p class="active">￥{{ item.originprice }}</p>
            </li>
          </ul>
        </div>

        <!-- 加载域 -->
        <div class="top10">
          <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
          >
            <ul :class="isShow ? 'prolist2' : 'prolist1'">
              <li
                class="van-hairline--bottom van-hairline--right"
                v-for="(item, index) in proList"
                :key="index"
              >
                <img width="100%" :src="item.img1" alt="" />
                <div>
                  <h4 class="van-multi-ellipsis--l2">{{ item.proname }}</h4>
                  <p>￥{{ item.originprice }}</p>
                </div>
              </li>
              <!--  <li van-hairline--bottom>
            <img width="100%" src="https://m.360buyimg.com/babel/jfs/t1/59332/26/21998/98831/637e0c94E83447b09/13c817146eac42e5.jpg.webp" alt="">
            <div><h4>荣耀 11  pro+ 216</h4>
            <p>￥1999</p></div>
          </li>
           <li van-hairline--bottom>
            <img width="100%" src="https://m.360buyimg.com/babel/jfs/t1/59332/26/21998/98831/637e0c94E83447b09/13c817146eac42e5.jpg.webp" alt="">
            <div><h4>荣耀 11  pro+ 216</h4>
            <p>￥1999</p></div>
          </li>
           <li van-hairline--bottom>
            <img width="100%" src="https://m.360buyimg.com/babel/jfs/t1/59332/26/21998/98831/637e0c94E83447b09/13c817146eac42e5.jpg.webp" alt="">
            <div><h4>荣耀 11  pro+ 216</h4>
            <p>￥1999</p></div>
          </li>
          <div class="toggle" @click="isShow=!isShow">
            <van-icon name="bars"  v-if="isShow"/>
             <van-icon name="apps-o" v-else/>  
          </div> -->
              <div class="toggle" @click="isShow = !isShow">
                <van-icon name="bars" v-if="isShow" />
                <van-icon name="apps-o" v-else />
              </div>
            </ul>
          </van-list>
        </div>
      </van-pull-refresh>
      <div class="top" v-if="scrollTop > 700" @click="backTop">
        <van-icon name="back-top" />
      </div>
    </div>
  </div>
</template>

<script>
import {
  getBannerList,
  getNavList,
  getSeckillList,
  getProList,
} from "../api/home";
import Vue from "vue";
import {
  Search,
  Swipe,
  SwipeItem,
  Grid,
  GridItem,
  CountDown,
  Image as VanImage,
  List,
  Icon,
  PullRefresh,
 
} from "vant";
Vue.use(Search);
Vue.use(Swipe);
Vue.use(SwipeItem);
Vue.use(Grid);
Vue.use(GridItem);
Vue.use(CountDown);
Vue.use(VanImage);
Vue.use(Icon);
Vue.use(List);
Vue.use(PullRefresh);

export default {
  name: "Home",
  components: {},
  data() {
    return {
      navList: [],
      bannerList: [],
      time: 24 * 60 * 60 * 600,
      seckillList: [],
      proList: [],
      isShow: true,
      loading: false,
      finished: false,
      count: 2,
      isLoading: false,
      scrollTop: 0,
      timer: null,
      value:''
      
    };
  },
  methods: {
    onLoad() {
      this.loading = true;
      setTimeout(() => {
        getProList({ count: this.count, limitNum: 12 }).then((data) => {
          console.log(data.data.data);
          this.loading = false;
          if (data.data.data.length == 0) {
            this.finished = true;
          } else {
            this.proList = [...this.proList, ...data.data.data];
            this.count++;
          }
        });
      }, 1500);
    },
    jumpTo(proid) {
      this.$router.push("/detail/" + proid);
    },
    onRefresh() {
      setTimeout(() => {
        this.isLoading = false;
        getProList().then((data) => {
          //  加载的第一页
          this.proList = data.data.data;
          this.count = 2;
        });
      }, 1000);
    },
    scrollMe() {
      this.scrollTop = this.$refs.main.scrollTop;
    },
    backTop() {
      this.timer = setInterval(() => {
        if (this.$refs.main.scrollTop <= 0) {
          clearInterval(this.timer);
        }
        this.$refs.main.scrollTop -= 100;
      }, 15);
    },
    toLogin(){
      this.$router.push("/login")
    },
    Gohome(){
      this.$router.push("/homecaty")
    },
   
  },
  created() {
    // 获取数据
    getBannerList().then((res) => {
      this.bannerList = res.data;
    });
    getNavList().then((res) => {
      this.navList = res.data;
    });
    getSeckillList().then((res) => {
      console.log(res.data.data);
      this.seckillList = res.data.data;
    });
    getProList({ count: this.count, limitNum: 12 }).then((data) => {
      console.log(data.data.data);
      this.proList = data.data.data;
    });
  },
};
</script>
<style scoped>
.header {
  width:3.76rem;
  height: 54px;
  display: flex;
}
.header_one {
  width: 50px;
padding-left: 10px;
padding-top: 10px;
background-color: #ee0a24;
font-family:"楷体";
}
.header_two {
  margin: auto;
}
.header_three {
 width: 50px;
padding-left: 10px;
padding-top: 10px;
background-color: #ee0a24;
font-family:"楷体";
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 150px;
  text-align: center;
  background-color: #39a9ed;
}
.my-swipe {
  height: 1.8rem;
}
.my-swipe img {
  height: 100%;
}
.top10 {
  margin-top: 0.1rem;
  min-height: 0.2rem;
  background-color: #fff;
}
.colon {
  display: inline-block;
  margin: 0 4px;
  color: #ee0a24;
}
.block {
  display: inline-block;
  width: 22px;
  color: #fff;
  font-size: 12px;
  text-align: center;
  background-color: #ee0a24;
}
.seckill {
  display: flex;
  justify-content: space-between;
}
.active {
  color: red;
}
.prolist1 {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
}
.prolist1 li {
  width: 49%;
}

.prolist2 li {
  display: flex;
}
.prolist2 li img {
  width: 32%;
  height: 0.8rem;
}
.prolist2 li div {
  flex: 1;
}
.toggle {
  width: 0.3rem;
  height: 0.3rem;
  border: 1px solid black;
  border-radius: 50%;
  position: fixed;
  bottom: 0.5rem;
  right: 0.2rem;
  text-align: center;
  line-height: 0.3rem;
}
.top {
  width: 0.3rem;
  height: 0.3rem;
  border: 1px solid black;
  border-radius: 50%;
  position: fixed;
  bottom: 1rem;
  right: 0.2rem;
  text-align: center;
  line-height: 0.3rem;
}
.djs{
  width: 100%;
  height: 30px;
  display: flex;
}
.djs-one{
  width: 20%;
   height: 30px;
    padding-top: 10px;
    color: #ee0a24;
}
.djs .top10{
  width: 30%;
}
.djs-two{
   width: 50%;
   height: 30px;
   padding-left: 50px;
   padding-top: 10px;
   color: #ee0a24;
}

</style>
